package Thread;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-02-09
 * Time: 20:34
 */
class MyCounter{
     volatile public int flag = 0;
}
public class Thread16 {
    public static void main(String[] args) {
        MyCounter myCounter = new MyCounter();
        Thread t1 = new Thread(() ->{
            while (myCounter.flag == 0){
                //循环体空着

            }
            System.out.println("t1循环结束");
        });
        Thread t2 = new Thread(() ->{
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入一个整数:");
            myCounter.flag = scanner.nextInt();
        });
        t1.start();
        t2.start();
    }
}
